/*******************************************************************************
 *
 *    Copyright (c) Baina Info Tech Co. Ltd
 *
 *    faplayer
 * 
 *    TimeFormater
 *    TODO File description or class description.
 *
 *    @author: zhbpeng
 *    @since:  2011-2-18
 *    @version: 1.0
 *
 ******************************************************************************/
package com.sdk.formatter;



/**
 * TimeFormater of faplayer.
 * @author zhbpeng
 *
 */

public class TimeFormater {

    /**
     * use microseconds as time unit
     * @param context
     * @param microseconds
     * @return
     */
    public static String getDisplayTime(final double microseconds){
        final double secs = microseconds / 1000 / 1000;
        return getDisplayTimeAtSecond(secs);
    }

    public static String getDisplayTimeAtSecond(final double secs){
        final long hour = (long) (secs / 3600);
        long remainder = (long) (secs % 3600);
        final long minute = remainder / 60;
        remainder = remainder % 60;
        final long second = remainder;
        final StringBuilder builder = new StringBuilder();
        if(hour > 0){
            if(hour > 0 && hour < 10){
                builder.append("0"+hour);
            }else{
                builder.append(hour);
            }
            builder.append(":");
        }
        if(minute >= 0 && minute < 10){
            builder.append("0"+minute);
        }else{
            builder.append(minute);
        }
        builder.append(":");
        if(second >= 0 && second < 10){
            builder.append("0"+second);
        }else{
            builder.append(second);
        }

        return builder.toString();
    }

    public static String formatIntervalSecond(final int second){
        final StringBuilder builder = new StringBuilder();
        final int minute = second / 60;
        final int lessSecond = second % 60;
        if(minute >= 0 && minute < 10){
            builder.append("0"+minute);
        }else{
            builder.append(minute);
        }
        builder.append(":");
        if(lessSecond >=0 && lessSecond < 10){
            builder.append("0"+lessSecond);
        }else{
            builder.append(lessSecond);
        }

        return builder.toString();
    }
}
